package com.power.util;

import com.power.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * 认证授权的工具类
 */
public class AuthUtils {


    /**
     * 获取安全认证框架的用户对象
     *
     * @return
     */
    public static SecurityUser getLoginSecurityUser() {
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取安全认证框架的权限
     * @return
     */
    public static Set<String> getLoginSecurityUserPerms(){
        return getLoginSecurityUser().getPerms();
    }

    /**
     * 从容器中获取id
     */
    public static  Long getLoginSecurityUserId(){
        return getLoginSecurityUser().getUserId();
    }

}
